package com.zhou.jiancai.fragment;


import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.hitomi.cmlibrary.CircleMenu;
import com.hitomi.cmlibrary.OnMenuSelectedListener;
import com.hitomi.cmlibrary.OnMenuStatusChangeListener;
import com.zhou.jiancai.R;
import com.zhou.jiancai.Utils.LogUtils;
import com.zhou.jiancai.activity.CalendarActivity;
import com.zhou.jiancai.activity.CircleViewActivity;
import com.zhou.jiancai.activity.EntBusTestActivity;
import com.zhou.jiancai.activity.GestureActivity;
import com.zhou.jiancai.activity.JCListActivity;
import com.zhou.jiancai.activity.MyMapActivity;
import com.zhou.jiancai.activity.PopWindowActivity;
import com.zhou.jiancai.activity.QRcodeActivity;
import com.zhou.jiancai.activity.ShowcaseActivity;
import com.zhou.jiancai.activity.SpiderActivity;
import com.zhou.jiancai.activity.StepsTellActivity;
import com.zhou.jiancai.activity.UCropActivity;
import com.zhou.jiancai.adapter.FragAdapter;
import com.zhou.jiancai.fragment.tablayoutFragment.RecommendFragment;
import com.zhou.jiancai.fragment.tablayoutFragment.HandTravelFragment;
import com.zhou.jiancai.fragment.tablayoutFragment.AmusementFragment;
import com.zhou.jiancai.fragment.tablayoutFragment.PlaymentFragment;
import com.zhou.jiancai.fragment.tablayoutFragment.FunPlayFragment;
import com.zhou.jiancai.ui.WrepContentHeightViewPager;
import com.zhou.jiancai.holder.RecycleViewHolder;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.ButterKnife;
import cn.bingoogolapple.bgabanner.BGABanner;

/**
 * Created by Administrator on 2017/1/10.
 */
public class PariseFragment extends Fragment implements View.OnClickListener {



    TabLayout tabs;

    AppBarLayout appbar;
 /*   @InjectView(R.id.toolbar)
    Toolbar toolbar;*/


    ViewPager viewPager;

    private RecyclerView recyclerView;
    public static final int HEADER = 0;
    CoordinatorLayout mainContent;
    private View view;
    private String[] titles;
    private List<View> listTitles;
    private FloatingActionButton floatingActionButton;
    private ArrayList list = new ArrayList();
    private RecyclerView recyclerView1;

    private SwipeRefreshLayout swiperefreshlayout;

    private Message msg;
    private ArrayList alist;
    private ArrayList clist;
    private ArrayList blist;


    // private ViewPager vp_banner;

    private int currentPosition=0;
    private ArrayList<ImageView> mImageViewList;
    private BGABanner vp_banner;
   // private WrepContentHeightViewPager vp_frag_praise;
    private ViewPager vp_frag_praise;

    @Nullable

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_product, null);
        //左上角图片点击事件
       ImageView agentweb= (ImageView) view.findViewById(R.id.agentweb);
        agentweb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "点击了左上图片", Toast.LENGTH_SHORT).show();
            }
        });
        //搜索点击事件
      TextView search= (TextView) view.findViewById(R.id.search);
        search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "点击了搜索", Toast.LENGTH_SHORT).show();
            }
        });
        //右上角左图片
        ImageView history= (ImageView) view.findViewById(R.id.history);
        history.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "点击了游戏中心", Toast.LENGTH_SHORT).show();
            }
        });
        //右上角右图片
        ImageView playcenter= (ImageView) view.findViewById(R.id.playcenter);
        playcenter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "点击了历史记录", Toast.LENGTH_SHORT).show();
            }
        });


       // vp_frag_praise = (WrepContentHeightViewPager) view.findViewById(R.id.vp_frag_praise);
        vp_frag_praise = (ViewPager) view.findViewById(R.id.vp_frag_praise);



       // initData();//初始化recycleview的数据
        initView();




        ButterKnife.inject(this, view);


        return view;
    }

/*获取远程数据*/
    private void getRemoteData() {
    }



    private void initRecycleView() {




   /*     swiperefreshlayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                ///刷新
                mHandler.sendEmptyMessageDelayed(REFRESH_COMPLETE, 2000);//演示网络缓慢
                // vp_banner.setCurrentItem(pics[0]);

            }
        });*/





    }










    private void initView() {

        initCircleView();


        initTabLayout();
       // initViewpagerData();
        initViewPager();

        // tabs.setupWithViewPager(viewPager);


    }





    private void initViewPager() {
        //构造适配器
        List<Fragment> fragments=new ArrayList<Fragment>();
        //这里使用单利增强性能
       fragments.add( new RecommendFragment(getActivity()));//推荐
        fragments.add(HandTravelFragment.getInstance());//手游
        fragments.add( FunPlayFragment.getInstance());//趣玩
        fragments.add(PlaymentFragment.getInstance());//游戏
        fragments.add(new AmusementFragment(getActivity()));//娱乐

        //设置viewpager的Fragmentpageadapter
        FragAdapter adapter = new FragAdapter(getActivity().getSupportFragmentManager(), fragments,titles);

        vp_frag_praise.setAdapter(adapter);
        //*设置最多的加载页*/
        vp_frag_praise.setOffscreenPageLimit(1);
        tabs.setupWithViewPager(vp_frag_praise);


    }

    private void initCircleView() {
        CircleMenu circleMenu = (CircleMenu) view.findViewById(R.id.circle_menu);

        circleMenu.setMainMenu(Color.parseColor("#CDCDCD"), R.mipmap.ic_launcher, R.mipmap.refreshed_icon)
                .addSubMenu(Color.parseColor("#258CFF"), R.drawable.ic_edit)
                .addSubMenu(Color.parseColor("#30A400"), R.drawable.ic_search)
                .addSubMenu(Color.parseColor("#FF4B32"), R.drawable.ic_favorite)
                .addSubMenu(Color.parseColor("#8A39FF"), R.drawable.ic_place)
                .addSubMenu(Color.parseColor("#FF6A00"), R.drawable.ic_search)
                .setOnMenuSelectedListener(new OnMenuSelectedListener() {//子选项的点击监听

                    @Override
                    public void onMenuSelected(int index) {
                        Intent intent;
                        switch (index) {

                            case 0:
                              /*  Toast.makeText(getActivity(), "currentpotion 上边" + 0, Toast.LENGTH_SHORT).show();
                                //存在问题
                                 intent=new Intent(getActivity(),SpiderActivity.class);

                                startActivity(intent);*/

                                break;
                            case 1:
                                Toast.makeText(getActivity(), "currentpotion 右上" + 1, Toast.LENGTH_SHORT).show();
                                intent=new Intent(getActivity(),UCropActivity.class);

                                startActivity(intent);

                                break;
                            case 2:
                                Toast.makeText(getActivity(), "currentpotion右下" + 2, Toast.LENGTH_SHORT).show();
                                intent=new Intent(getActivity(),QRcodeActivity.class);

                                startActivity(intent);
                                break;
                            case 3:
                                Toast.makeText(getActivity(), "currentpotion左下" + 3, Toast.LENGTH_SHORT).show();
                                intent=new Intent(getActivity(),JCListActivity.class);

                                startActivity(intent);
                                break;
                            case 4:
                                Toast.makeText(getActivity(), "currentpotion左上" + 4, Toast.LENGTH_SHORT).show();
                                intent=new Intent(getActivity(),CalendarActivity.class);

                                startActivity(intent);
                                break;


                        }
                    }

                }).setOnMenuStatusChangeListener(new OnMenuStatusChangeListener() {

            @Override
            public void onMenuOpened() {

            }

            @Override
            public void onMenuClosed() {

            }

        });
    }


    private void initTabLayout() {
        //给TabLayout增加Tab, 并关联ViewPager
        titles = new String[]{"推荐", "手游","趣玩" , "游戏", "娱乐"};//, "NBA", "搞笑", "科技", "创业"
        tabs = (TabLayout) view.findViewById(R.id.tabs);

        listTitles = new ArrayList<>();
        tabs.setTabMode(TabLayout.MODE_FIXED);
        for (int i = 0; i < titles.length; i++) {


            TextView textView = new TextView(getActivity());
            textView.setText(titles[i]);
            textView.setTextColor(Color.BLUE);
            listTitles.add(textView);

            tabs.addTab(tabs.newTab().setText(titles[i]));//给引导indicator添加tab

        }





    }


    @Override
    public void onClick(View v) {

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }



}